package server.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import server.model.entity.ShopOrderItem;
import server.model.entity.Sign;
import server.model.entity.Users;

import java.math.BigDecimal;
import java.util.List;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
public interface UsersDao extends JpaRepository<Users, String> {
    Users findByMobile(String mobile);

    Users findByUserName(String userName);

    @Modifying
    @Query(value = "select * from users where tree like CONCAT('%', ?1, '%')", nativeQuery = true)
    List<Users> findByTreeLike(String userId);

    List<Users> findByNameLike(String name);

    List<Users> findByParentId(String parentId);

    List<Users> findByIdInOrderByTreeNumDesc(List<String> userIds);

    @Query(value = "select * from users where DATE_FORMAT(create_time,'%Y-%m-%d') = ?1", nativeQuery = true)
    List<Users> findTime(String time);

    @Modifying
    @Query(value = "update users set performance = performance + :py where id in(:userIds)", nativeQuery = true)
    Integer updateAddByUserId(@Param("userIds") List<String> userIds, @Param("py") Integer py);

    @Modifying
    @Query(value = "select * from users where id not in (select user_id from user_site) ", nativeQuery = true)
    List<Users> findNoK();
}
